import React from 'react';
import {checkLogin,logout} from './../../api';
import {remove,set,get} from './../../store';

export default class top extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
    	loginStatus: get('login_status')
    }
    this.LogOut = this.LogOut.bind(this);
  }

  LogOut(event) {
  	logout().then(resp=>{
  		console.info(resp);
  		if(resp.content) {
  			remove('_user');
  			remove('login_status');
  			remove('token');
  			remove('username');
  			window.location.reload(true); 
  		} else {
  			remove('login_status');
  			window.location.href="/login";
  		}
  	});
  }

  render() {
    return (
	    <div className="loginheader">
	    	<div className="header">
				<div className="headertitle">码客山威</div>
				<ul className="headerul">
				{
				/*	<li><a href="/">首页</a></li>
					<li>|</li>*/
				}
					<li><a href="/home">论坛</a></li>
					<li>|</li>
					<li><a href="/">博客</a></li>
					<li>|</li>
					<li><a href="">网盘</a></li>
					<li>|</li>
				
					<li><a href="/personal">个人中心</a></li>
					<li>|</li>
					<li><a href="">大赛平台</a></li>
				{
					this.state.loginStatus=="true"?(<span><li>|</li><li><a href="javascript:void()" onClick={this.LogOut.bind(this)}>退出登录</a></li></span>):<span><li>|</li><li><a href="/login" >登录</a></li></span>
				}
				</ul>
			</div>			
		</div>
    );
  }
}